#!/bin/ksh

LOGIN=$1
SH_DIR=$2
SH_FILE=$3
UP_DIR=$4
UP_FILE=$5
BU_TYPE=$6
echo $LOGIN LOGIN
sqlplus -s $LOGIN<<!
DELETE FROM ccs.ccs_ams_tmp_disc_acc;
COMMIT;
!

if [  $BU_TYPE = "DMB" -o $BU_TYPE = "3MB" ]; then 
cat > $UP_DIR/ctl/$SH_FILE.ctl<<!
LOAD DATA
INFILE '$UP_DIR/$UP_FILE'
APPEND INTO TABLE CCS.CCS_AMS_TMP_DISC_ACC
FIELDS TERMINATED BY ';' optionally enclosed '"'
TRAILING NULLCOLS
(
UBACCNO,
ACC_NO,
NAME,
MOBILE,
TOB, 
DET_DATE DATE "dd/mm/yyyy",
DIS_REA,
CUST_CLASS,
LAST_INVO DATE "dd/mm/yyyy",
NETWORK,
CYCLE,
UBSTATUS,
HOLD_BILL,
RDIS_DATE DATE "dd/mm/yyyy",
BILL_STUS,
CONT_PRICE,
CONT_CODE,
PLAN_DATE DATE "dd/mm/yyyy"
)
!
fi   

if [ $BU_TYPE = "DUB" -o  $BU_TYPE = "3UB" ]; then 
cat > $UP_DIR/ctl/$SH_FILE.ctl<<!
LOAD DATA
INFILE '$UP_DIR/$UP_FILE'
APPEND INTO TABLE CCS.CCS_AMS_TMP_DISC_ACC
FIELDS TERMINATED BY ',' optionally enclosed '"'
TRAILING NULLCOLS
(
UBACCNO,
ACC_NO,
NAME,
MOBILE,
TOB, 
DET_DATE DATE "yyyymmdd",
DIS_REA,
CUST_CLASS,
LAST_INVO DATE "yyyymmdd",
NETWORK,
CYCLE,
UBSTATUS,
HOLD_BILL,
RDIS_DATE DATE "dd/mm/yyyy",
BILL_STUS,
CONT_PRICE,
CONT_CODE,
PLAN_DATE DATE "dd/mm/yyyy"
)
!
fi 

/usr/local/bin/dos2unix $UP_DIR/$UP_FILE

sqlldr $LOGIN \
control=$UP_DIR/ctl/$SH_FILE.ctl bad=$UP_DIR/bad/$SH_FILE.bad \
log=$UP_DIR/log/$SH_FILE.log >> $UP_DIR/log/$SH_FILE.log
